package repositories;

import java.util.Collection;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Customer;

@Repository
public interface CustomerRepository extends JpaRepository<Customer, Integer> {
	@Query("select c from Customer c where c.userAccount.id = ?1")
	Customer findByUserAccountId(int userAccountId);

	@Query("select c from Customer c where c.userAccount.username = ?1")
	Customer findByUsername(String username);

	@Query("select c from Customer c where c.paintings.size=(select max (cc.paintings.size)from Customer cc)")
	Collection<Customer> findByMorePaintings();

	@Query("select c from Customer c where c.comments.size=(select max (cc.comments.size)from Customer cc)")
	Collection<Customer> findByMoreComments();
	
	@Query("select c from Customer c join c.ownershipHistories h where h.painting.id=?1 and h.actualOwner = true")
	Customer findOwnerByPaintingId(int paintingId);
	

}
